package de.hm.edu.cep;

import java.util.ArrayList;
import java.util.Date;
import java.util.UUID;

/**
 * This class represents a KPIEvent event
 *
 * @author Peter Goldenbogen (Munich University of Applied Science)
 * @version 1.0
 */
public class KPIEvent {

	private UUID id;
	/**A list of events that directly caused the event to happen*/
	private final ArrayList<UUID> causality = new ArrayList<UUID>();
	/**actual system time when the event was created*/
	private Date timestamp;
	/**The amount of products that have been ordered */
	private int amount;
	
	public KPIEvent(){
		super();
		this.id = UUID.randomUUID();
		this.timestamp = new Date(System.currentTimeMillis());
	}
	
	public KPIEvent(int amount, ArrayList<UUID> causality){
		super();
		this.amount = amount;
		this.id = UUID.randomUUID();
		this.timestamp = new Date(System.currentTimeMillis());
		
		if(causality != null)
			this.causality.addAll(causality);
	}
	
	/**
	 * Get all stored causality entries
	 * 
	 * @return a deep copy of the causality ArrayList Collection
	 * */
	public ArrayList<UUID> getCausality() {
		
		ArrayList<UUID> rCausality = new ArrayList<UUID>();
		
		for(UUID id: this.causality){
			rCausality.add(id);
		}
		
		return rCausality;
	}

	public UUID getId() {
		return id;
	}

	public void setId(UUID id) {
		this.id = id;
	}

	public Date getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(Date timestamp) {
		this.timestamp = timestamp;
	}

	public int getAmount() {
		return amount;
	}

	public void setAmount(int amount) {
		this.amount = amount;
	}

	@Override
	public String toString() {
		return "KPIEvent [id=" + id + ", causality=" + causality
				+ ", timestamp=" + timestamp + ", amount=" + amount + "]";
	}
}
